import figlet from "figlet";
import fs from "fs";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
import { promisify } from "util";

const packageJsonUrl = resolve(dirname(fileURLToPath(import.meta.url)), "../../package.json");
const packageJsonStr = fs.readFileSync(packageJsonUrl, "utf-8");
const packageModule = JSON.parse(packageJsonStr);

const figletPromise = promisify(figlet.text);

/**
 * 返回 logo 字符串
 * @returns {string} logo
 * @example
 * const logo = getLogo();
 * console.log(logo);
 */
export default function getLogo() {
    // try {
    //     const data = await figletPromise(packageModule.name, {
    //         font: "Ghost",
    //         horizontalLayout: "default",
    //         verticalLayout: "default",
    //         width: 80,
    //         whitespaceBreak: true
    //     });
    //     return data;
    // } catch (error) {
    //     return Promise.reject(error);
    // }

    const logo = figlet.textSync(packageModule.name, {
        font: "Ghost",
        horizontalLayout: "default",
        verticalLayout: "default",
        width: 120,
        whitespaceBreak: true
    });

    return `
    ${logo}
    

    `;
}
